package cn.jtool.dig.server.comm.real;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RealChannelInitializer extends ChannelInitializer<Channel> {

    private final RealConnHander realConnHander;

    private final RealDataHander realDataHander;

    @Resource
    private RealOutHander realOutHander;

    public RealChannelInitializer(RealConnHander realConnHander, RealDataHander realDataHander) {
        this.realConnHander = realConnHander;
        this.realDataHander = realDataHander;
    }

    @Override
    protected void initChannel(Channel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast("connectHandler", this.realConnHander);
        pipeline.addLast("dataHandler", this.realDataHander);
        pipeline.addLast("outHandler", this.realOutHander);
    }
}
